package br.com.werp.regras.geral.integracao;

import java.sql.Connection;
import java.util.List;
import java.util.ResourceBundle;

import br.com.werp.regras.geral.util.Constantes;
import br.com.werp.regras.geral.vos.tabelas.Hd;

/**
 * @author Candido
 * Criado em  11/01/2005
 */
public class HdDAO extends MasterDAO{
	
	private static HdDAO hdDAO;

    /**
     * @param banco
     * @throws Exception
     */
    private HdDAO(String banco) throws Exception {
        super(banco);
    } 
    
    public static HdDAO getHdDAO() throws Exception {
        if (hdDAO == null) {
            ResourceBundle bundle = ResourceBundle.getBundle(Constantes.CONFIG);
            hdDAO = new HdDAO(bundle.getString(Constantes.BANCO));
        }

        return hdDAO;
    }


    /**
     * @param hdId
     * @return
     * @throws Exception
     */
    public Hd obterHd(String hdId) throws Exception {
        return obterHd(getConexao(), hdId);
    }

    public Hd obterHd(Connection conexao, String hdId) throws Exception {
        Connection conn = null;
        try {
            conn = (Connection) conexao;

            List l =
                preencheVO(conn, new Hd(), " hadk_id = " + hdId);
            if (l.isEmpty())
                return null;
            return (Hd) l.get(0);
        } catch (Exception e) {
            throw e;
        } finally {
            if (conn.getAutoCommit())
                liberaConeccao(conn);
        }
    }
    
    
}
